<template>
  <div class="">
    <ul>
      <h1>正在进行 {{ num1 }}</h1>
      <li
        v-for="(item, index) in list"
        :key="index"
        v-show="item.status == false"
      >
        <!-- <input type="checkbox" v-model="item.status" /> -->
        <input type="checkbox" @change="change(index)" :checked="item.status" />

        <input
          v-if="index == flag"
          type="text"
          v-model="item.title"
          @blur="flag = -1"
        />
        <span v-else @dblclick="edit(index)">{{ item.title }}</span>
        <span @click="remove(index)">x</span>
      </li>
    </ul>
    <ul>
      <h1>已完成 {{ num2 }}</h1>
      <li
        v-for="(item, index) in list"
        :key="index"
        v-show="item.status == true"
      >
        <!-- <input type="checkbox" v-model="item.status" /> -->
        <input type="checkbox" @change="change(index)" :checked="item.status" />
        <span>{{ item.title }}</span>
        <span @click="remove(index)">x</span>
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  props: ["list"],
  //接收list
  data() {
    return {
      flag: -1,
      //保存双击编辑的下标
    };
  },
  mounted() {},
  methods: {
    remove(index) {
      this.$emit("remove", index);
    },
    //调用父组件的remove方法
    edit(index) {
      this.flag = index;
    },
    //把要修改的下标保存
    change(index) {
      this.$emit("change", index);
    },
    //调用父组件的change方法
  },
  components: {},
  computed: {
    num1() {
      let arr1 = this.list.filter((item) => {
        return item.status == false;
      });
      return arr1.length;
    },
    num2() {
      let arr1 = this.list.filter((item) => {
        return item.status == true;
      });
      return arr1.length;
    },
    //计算未完成 和 已完成的数量
  },
};
</script>

<style lang="scss"></style>
